package com.fulei.device;

import com.bjfl.saleManager.util.LogUtil;
import com.fulei.logic.JcmBillValidatorOperate;
import com.fulei.logic.MeiBillValidatorOperate;

public class BillAcceptor
{
  private String deviceType;
  private String comNo;
  private String baudRate;
  
  public BillAcceptor(String devType, String com, String brn)
  {
    this.deviceType = devType;
    this.comNo = com;
    this.baudRate = brn;
  }
  
  public int paperReset()
  {
    int return_data = 0;
    try
    {
      if ("MEIBILL1".equals(this.deviceType))
      {
        MeiBillValidatorOperate.comNo = this.comNo;
        MeiBillValidatorOperate.baudRate = this.baudRate;
        
        return_data = MeiBillValidatorOperate.Reset();
      }
      else if ("JCM1".equals(this.deviceType))
      {
        JcmBillValidatorOperate.comNo = this.comNo;
        JcmBillValidatorOperate.baudRate = this.baudRate;
        return_data = JcmBillValidatorOperate.ResetBill();
      }
    }
    catch (Exception ex)
    {
      LogUtil.writeExceptionLog("纸币器复位:" + ex.getMessage());
      return_data = -1;
    }
    return return_data;
  }
  
  public int paperPoll()
  {
    int return_data = 0;
    try
    {
      if ("MEIBILL1".equals(this.deviceType))
      {
        MeiBillValidatorOperate.comNo = this.comNo;
        MeiBillValidatorOperate.baudRate = this.baudRate;
        
        return_data = MeiBillValidatorOperate.mPoll();
      }
      else if ("JCM1".equals(this.deviceType))
      {
        JcmBillValidatorOperate.comNo = this.comNo;
        JcmBillValidatorOperate.baudRate = this.baudRate;
        return_data = JcmBillValidatorOperate.Poll();
      }
    }
    catch (Exception ex)
    {
      LogUtil.writeExceptionLog("接收纸币:" + ex.getMessage());
      return_data = -1;
    }
    return return_data;
  }
  
  public int paperEnable()
  {
    int return_data = 0;
    try
    {
      if ("MEIBILL1".equals(this.deviceType))
      {
        MeiBillValidatorOperate.comNo = this.comNo;
        MeiBillValidatorOperate.baudRate = this.baudRate;
        
        return_data = MeiBillValidatorOperate.mUseBill();
      }
      else if ("JCM1".equals(this.deviceType))
      {
        JcmBillValidatorOperate.comNo = this.comNo;
        JcmBillValidatorOperate.baudRate = this.baudRate;
        return_data = JcmBillValidatorOperate.SetRehibit();
      }
    }
    catch (Exception ex)
    {
      LogUtil.writeExceptionLog("接收纸币:" + ex.getMessage());
      return_data = -1;
    }
    return return_data;
  }
  
  public int paperDisabled()
  {
    int return_data = 0;
    try
    {
      if ("MEIBILL1".equals(this.deviceType))
      {
        MeiBillValidatorOperate.comNo = this.comNo;
        MeiBillValidatorOperate.baudRate = this.baudRate;
        
        return_data = MeiBillValidatorOperate.mRobitBill();
      }
      else if ("JCM1".equals(this.deviceType))
      {
        JcmBillValidatorOperate.comNo = this.comNo;
        JcmBillValidatorOperate.baudRate = this.baudRate;
        return_data = JcmBillValidatorOperate.InhibitAllBillType();
      }
    }
    catch (Exception ex)
    {
      LogUtil.writeExceptionLog("接收纸币:" + ex.getMessage());
      return_data = -1;
    }
    return return_data;
  }
  
  public int paperEnableAllBill()
  {
    int return_data = 0;
    try
    {
      if ("JCM1".equals(this.deviceType))
      {
        JcmBillValidatorOperate.comNo = this.comNo;
        JcmBillValidatorOperate.baudRate = this.baudRate;
        return_data = JcmBillValidatorOperate.UsefulAllBillType();
      }
    }
    catch (Exception ex)
    {
      LogUtil.writeExceptionLog("启用所有纸币类型:" + ex.getMessage());
      return_data = -1;
    }
    return return_data;
  }
  
  public int paperTemporary()
  {
    int return_data = 0;
    try
    {
      if ("MEIBILL1".equals(this.deviceType))
      {
        MeiBillValidatorOperate.comNo = this.comNo;
        MeiBillValidatorOperate.baudRate = this.baudRate;
        
        return_data = MeiBillValidatorOperate.mTemporary();
      }
    }
    catch (Exception ex)
    {
      LogUtil.writeExceptionLog("启用暂存:" + ex.getMessage());
      return_data = -1;
    }
    return return_data;
  }
}
